package com.jzy.bxb.app.scripts.http.config;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.jzy.bxb.app.server.AuthHttpHandler;
import com.jzy.bxb.core.handler.HandlerEntity;
import com.jzy.bxb.core.handler.HttpHandler;
import com.jzy.bxb.core.util.FileUtil;
import com.jzy.bxb.model.mongo.dao.ConfigCityDao;
import com.jzy.bxb.model.mongo.dao.ConfigProvinceDao;
import com.jzy.bxb.model.mongo.entity.config.ConfigCity;
import com.jzy.bxb.model.mongo.entity.config.ConfigCounty;
import com.jzy.bxb.model.mongo.entity.config.ConfigProvince;

/**
 * 省市區查詢
 * 
 * @author JiangZhiYong
 *         <p>
 *         http://127.0.0.1:8680/config/city?city=chengdu&sid=e8554461-b5e0-4c28-8bcc-1d2c1f316d3a
 *         http://112.74.36.233:8680/config/city?city=chengdu&sid=59a2b30d-b5d0-444a-82e8-c1ea87478df4
 *         <li>
 *         <li>city 城市</li>
 *         </p>
 */
@HandlerEntity(path = "/config/city")
public class QueryCityHandler extends AuthHttpHandler {

	@Override
	public void run() {
		String city = getString("city");
		if (city == null || "".equals(city.trim())) {
			List<String> names = ConfigCityDao.getCityNames();
			sendMsg(names);
			return;
		}
		ConfigCity configCity = ConfigCityDao.getConfigCity(city);
		if (configCity == null) {
//			if (city.equals("成都")) {
//				configCity = new ConfigCity();
//				configCity.setName("chengdu");
//				configCity.setProvince("四川");
//				List<ConfigCounty> countys = new ArrayList<>();
//				List<String> community = new ArrayList<>();
//				community.add("三利宅院");
//				community.add("君安卫士花园");
//				ConfigCounty configCounty = new ConfigCounty();
//				configCounty.setName("高新区");
//				configCounty.setCommunity(community);
//				countys.add(configCounty);
//				configCity.setCounty(countys);
//				ConfigCityDao.saveConfigCity(configCity);
//			}
			sendError(city + "还未实现服务");
		}
		sendMsg(configCity);
	}

}
